<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>目录编辑</title>

<%@include file="/WEB-INF/pages/common/head.jsp" %>

<script type="text/javascript" src="<%=root%>/plugin/jquery_tools/validator.js"></script>

<link rel="stylesheet" type="text/css" href="<%=root%>/plugin/flexigrid/css/flexigrid/flexigrid.css">
<script type="text/javascript" src="<%=root%>/plugin/flexigrid/flexiform.js"></script>
<script type="text/javascript">



function getCatalog() {
    //var params = {isSearch:true, onReturn:getCatalogOnReturn} ;
    
    openWindow({url:"<%=root%>/product/catalog_grid.action", name:"catalogSearchWindow", width:860, height:560}) ;
}

window.onload = function() {
    if (window.name == "updateCatalog") {
        editForm.action = "<%=root%>/product/catalog_update.action" ;
    } else {
        editForm.action = "<%=root%>/product/catalog_create.action" ;
    }
    
    init();

    $('#formTable').flexigrid(

            {
                buttons : [
                           {name :'保存',bclass:'save',onpress:doSave},
                           {separator : true},
                           {name :'重置',bclass:'reset',onpress:reset},
                           {name :'退出',bclass:'exit',onpress:closeMe}
                          ],
                usepager: false,
                title: '目录编辑',
                useRp: false,
                showTableToggleBtn: false,
                height:"auto",
                minwidth:500,
                singleSelect:true,
                multisel:false
            }
     );

    $("#editForm").validator();
}

function doSave() {
	if (editForm.checkValidity()) {
        top.$.post(editForm.action, top.$(editForm).serialize(), doSaveOnRetrun);
    } 
}

var isSaved = false ;
function doSaveOnRetrun(xml) {
	var error = xml2Object(xml).error ;
	
	if (!isUndefined(error)) {
        alert(error.innerText) ;
        return ;
    }
	isSaved = true ;
	alert("保存成功!") ;
	if (window.name == "updateCatalog") {
        window.close() ;
	} else {
		reset();
    }
}

window.onunload = function () {
    
    if (isSaved && isDefined(opener.formWindowOnClose)) {
    	opener.formWindowOnClose(editForm) ;
    }

    unblock();
}

function gridWindowOnSelected(rowData) {
	editForm['catalog.domain_'].value = xml2Object(rowData).domain_.innerText;
}

function closeMe() {
	window.close() ;
}

function reset() {
	editForm.reset() ;
	init();
}

function init() {
	if (window.name == "updateCatalog") {
        opener.dataGrid.fillEditForm(editForm) ;
        editForm['catalog.pro_catalog_name'].value = opener.pro_name ;
	} else {
	    editForm['catalog.pro_catalog_id'].value = opener.pro_id ;
	    editForm['catalog.level_'].value = opener.level ;
	    editForm['catalog.pro_catalog_name'].value = opener.pro_name ;
	}
}
</script>
</head>
<body topmargin="0" leftmargin="0">
<div class=".pReloa"></div>
  <form action="" method="post" name="editForm" id="editForm">
      <input type="hidden" name="catalog.catalog_id"/>
      <table id="formTable" height="100%" width="100%">
        <tbody>
          <tr><td width="400">pro_id:</td></tr>
          <tr><td><input type="text" name="catalog.pro_catalog_name" readonly="readonly"/><input type="hidden" name="catalog.pro_catalog_id"/></td></tr>
          <tr><td>name:</td></tr>
          <tr><td><input type="text" name="catalog.name_"  required="required" /></td></tr>
          <tr><td>desc:</td></tr>
          <tr><td><input type="text" name="catalog.desc_"/></td></tr>
          <tr><td>level:</td></tr>
          <tr><td><input type="text" name="catalog.level_" readonly="readonly"/></td></tr>
          <tr><td>index:</td></tr>
          <tr><td><input type="integer" name="catalog.index_" min="1"/></td></tr>
          <!-- 
          <tr>
            <td>
              <input type="button" name="save" value="save" onclick="doSave()"/>
              &nbsp;&nbsp;
              <input type="button" name="close" value="close" onclick="closeMe()"/>
              <input type="submit" name="submit"/>
            </td>
          </tr>
           -->
        </tbody>
      </table>
  </form>
</body>
</html>